<template>
  <!--采购申请-->
  <div style="padding: 20px">
    <el-card class="box-card56">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="全部" name="first"><el-button @click="handleNew">新增</el-button>
          <el-button @click="handleDelete">删除</el-button>
          <el-input placeholder="请输入设备编号或名称" v-model="searchText" clearable prefix-icon="el-icon-search"
            suffix-icon="el-icon-s-cale" @input="handleSearcha" style="width: 250px; margin-left: 660px" />
          <el-popover placement="right" width="400" trigger="click">
            <svg-icon icon-class="caiss" style="width: 40px; height: 20px" class="pointer" slot="reference" />
          </el-popover>
          <el-table :data="filteredData" style="width: 100%; margin-top: 20px" header-align="center" align="center">
            <el-table-column type="selection" width="55" fixed align="center" />
            <el-table-column label="序号" width="70" align="center" fixed>
              <template v-slot="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="80" align="center" fixed>
              <template v-slot="scope">
                <el-button type="text" @click="handleView(scope.row)">查看</el-button>
              </template>
            </el-table-column>
            <el-table-column label="状态" width="80" align="center">
              <template slot-scope="scope">
                <el-tag type="success" effect="dark" v-if="scope.row.state == 1">待审核</el-tag>
                <el-tag type="warning" effect="dark" v-if="scope.row.state == 2">未通过</el-tag>
                <el-tag type="danger" effect="dark" v-if="scope.row.state == 3">待采购</el-tag>
                <el-tag type="success" effect="dark" v-if="scope.row.state == 4">采购中</el-tag>
                <el-tag type="warning" effect="dark" v-if="scope.row.state == 5">已完成</el-tag>
                <el-tag type="danger" effect="dark" v-if="scope.row.state == 6">已撤销</el-tag>
                <el-tag type="danger" effect="dark" v-if="scope.row.state == 7">审核通过</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="code" label="申请单号" width="200" align="center" />
            <el-table-column prop="topic" label="申请主题" width="200" align="center" />
            <el-table-column prop="date" label="申请时间" width="180" align="center" />
            <el-table-column prop="applicant" label="申请人" width="100" align="center" />
            <el-table-column prop="department" label="申请部门" width="100" align="center" />
            <el-table-column prop="contact" label="联系方式" width="200" align="center" />
            <el-table-column prop="affair" label="申请事由" width="200" align="center" />
            <el-table-column prop="quantity" label="申请采购数量" width="100" align="center" />
            <el-table-column prop="amount" label="预计总金额" width="100" align="center" />
            <el-table-column prop="remark" label="备注" width="200" align="center" />
          </el-table>

          <el-pagination background :current-page.sync="currentPage" :page-size="pageSize" :total="total"
            layout="prev, pager, next, sizes, total" :page-sizes="[10, 20, 30, 50]" @size-change="handleSizeChange"
            @current-change="handleCurrentChange" /></el-tab-pane>
        <el-tab-pane label="我的申请" name="second">我的申请</el-tab-pane>
        <el-tab-pane label="我的审批" name="third">我的审批</el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import {
  SelectApplication,
  SelectApplication2,
  SelectApplicationk
} from "@/api/eastjet-maintenance/caig/cai";
import Index from "../type/index.vue";
export default {
  data() {
    return {
      //卡片信息
      activeName: "first",
      searchText: "",
      filteredData: [],
      currentPage: 1,
      pageSize: 10,
      total: 45,
      form: {
        "code": "",
        "quantity": "",
        "amount": "",
        "topic": "",
        "applicant": "",
        "department": "",
        "contact": "",
        "affair": "",
        "state": "",
        "state": "",
      },
      kan: {
        code: "",
        pan: "1"
      }
    };
  },

  created() {
    this.getList();
  },
  methods: {
    handleSizeChange(size) {
      this.pageSize = size;
      SelectApplicationk(this.currentPage, this.pageSize).then((res) => {
        this.filteredData = res.data.data.list;
        this.total = res.data.data.total;
      });
      console.log(`每页 ${size} 条`);
    },
    handleCurrentChange(page) {
      this.currentPage = page;
      SelectApplicationk(this.currentPage, this.pageSize).then((res) => {
        this.filteredData = res.data.data.list;
        this.total = res.data.data.total;
      });
      console.log(`当前页: ${page}`);
    },
    handleSearcha() {
      this.form.code = this.searchText;
      SelectApplication(this.form).then((response) => {
        this.filteredData = response.data.data.list;
        // this.Index();
      });
    },
    getList() {
      SelectApplication(this.kan).then((response) => {
        console.log("feny", response)
        this.filteredData = response.data.data.list;
        this.total = response.data.data.total;
      });
    },
    //卡片选择信息
    handleClick(tab, event) {
      console.log("卡片", tab, event);
    },
    handleSearch() {
      this.currentPage = 1;
    },
    handleNew() {
      // 处理新增操作
      // this.form.data = this.filteredData;
      this.$router.push({ path: "/sb/yan/dang/xin" });
      // SelectApplication2(this.form).then((response) => {});
    },
    handleDelete() {
      // 处理删除操作
    },
    handleView(row) {
      // 查看具体信息

      this.$router.push({
        path: "/sb/yan/dang/cha",
        query: { code: row.code },
      });
      // this.$router.push({ path: "/sb/yan/dang/cha" });
    },
    handlePageChange(page) {
      this.currentPage = page;
    },
  },
};
</script>

<style>
/* 自定义样式 */
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card56 {
  width: 1210px;
  margin-left: 14px;
}
</style>
